#include "XmlSaver.h"

XmlSaver::XmlSaver(std::ostream &s) : s(s)
{
	ident = 0;
}

void XmlSaver::SaveAnimationStart()
{
}

void XmlSaver::SaveAnimationEnd()
{
}

void XmlSaver::SaveAnimationPresent()
{
}

void XmlSaver::SaveAnimationNotPresent()
{
}

void XmlSaver::SaveStartNodes(int nodesCount)
{
	s << XmlElement::OpenTagWithAttribs("Nodes", ident);
	s << XmlElement::CreateLastAttrib<int>("Count", nodesCount);

	ident++;
}

void XmlSaver::SaveEndNodes()
{
	ident--;

	s << XmlElement::CloseTag("Nodes", ident);
}

void XmlSaver::SaveStartNode(int nodeId)
{
	s << XmlElement::OpenTagWithAttribs("Node", ident);
	s << XmlElement::CreateLastAttrib<int>("Id", nodeId);

	ident++;
}

void XmlSaver::SaveEndNode()
{
	ident--;

	s << XmlElement::CloseTag("Node", ident);
}

void XmlSaver::SavePositionBeginSection(int keysCount)
{
	s << XmlElement::OpenTagWithAttribs("PositionKeys", ident);
	s << XmlElement::CreateLastAttrib<int>("KeysCount", keysCount);

	ident++;
}

void XmlSaver::SavePositionKey(float time, float x, float y, float z)
{
	s << XmlElement::OpenTagWithAttribs("PositionKey", ident);
	s << XmlElement::CreateAttrib<float>("Time", time);
	s << XmlElement::CreateAttrib<float>("X", x);
	s << XmlElement::CreateAttrib<float>("Y", y);
	s << XmlElement::CreateLastAttrib<float>("Z", z, true);
}

void XmlSaver::SavePositionEndSection()
{
	ident--;

	s << XmlElement::CloseTag("PositionKeys", ident);
}

void XmlSaver::SaveRotationBeginSection(int keysCount)
{
	s << XmlElement::OpenTagWithAttribs("RotationKeys", ident);
	s << XmlElement::CreateLastAttrib<int>("KeysCount", keysCount);

	ident++;
}

void XmlSaver::SaveRotationKey(float time, float a, float x, float y, float z)
{
	s << XmlElement::OpenTagWithAttribs("RotationKey", ident);
	s << XmlElement::CreateAttrib<float>("Time", time);
	s << XmlElement::CreateAttrib<float>("Angle", a);
	s << XmlElement::CreateAttrib<float>("X", x);
	s << XmlElement::CreateAttrib<float>("Y", y);
	s << XmlElement::CreateLastAttrib<float>("Z", z, true);
}

void XmlSaver::SaveRotationEndSection()
{
	ident--;

	s << XmlElement::CloseTag("RotationKeys", ident);
}

void XmlSaver::SaveScaleBeginSection(int keysCount)
{
	s << XmlElement::OpenTagWithAttribs("ScaleKeys", ident);
	s << XmlElement::CreateLastAttrib<int>("KeysCount", keysCount);

	ident++;
}

void XmlSaver::SaveScaleKey(float time, float x, float y, float z)
{
	s << XmlElement::OpenTagWithAttribs("ScaleKey", ident);
	s << XmlElement::CreateAttrib<float>("Time", time);
	s << XmlElement::CreateAttrib<float>("X", x);
	s << XmlElement::CreateAttrib<float>("Y", y);
	s << XmlElement::CreateLastAttrib<float>("Z", z, true);
}

void XmlSaver::SaveScaleEndSection()
{
	ident--;

	s << XmlElement::CloseTag("ScaleKeys", ident);
}

void XmlSaver::SaveRollBeginSection(int keysCount)
{
}

void XmlSaver::SaveRollKey(float time, float v)
{
}

void XmlSaver::SaveRollEndSection()
{
}

void XmlSaver::SaveLocalTransformMatrix(float *v)
{
}


void XmlSaver::SaveObjectTransformMatrix(float *v)
{
}


void XmlSaver::SaveWorldTransformMatrix(float *v)
{
}


void XmlSaver::SaveInverseLocalTransformMatrix(float *v)
{
	/*Log::Get() << "Inversed Local Transform Matrix:\n";
	Log::Get() << nodeTM[0][0] << "\t" << nodeTM[1][0] << "\t" << nodeTM[2][0] << "\t" << nodeTM[3][0] << "\n";
	Log::Get() << nodeTM[0][1] << "\t" << nodeTM[1][1] << "\t" << nodeTM[2][1] << "\t" << nodeTM[3][1] << "\n";
	Log::Get() << nodeTM[0][2] << "\t" << nodeTM[1][2] << "\t" << nodeTM[2][2] << "\t" << nodeTM[3][2] << "\n";	
	Log::Get() << nodeTM[0][3] << "\t" << nodeTM[1][3] << "\t" << nodeTM[2][3] << "\t" << nodeTM[3][3] << "\n";
	Log::Get() << "\n";*/
}

void XmlSaver::SaveInverseObjectTransformMatrix(float *v)
{
	/*Log::Get() << "Inversed Object Transform Matrix:\n";
	Log::Get() << nodeTM[0][0] << "\t" << nodeTM[1][0] << "\t" << nodeTM[2][0] << "\t" << nodeTM[3][0] << "\n";
	Log::Get() << nodeTM[0][1] << "\t" << nodeTM[1][1] << "\t" << nodeTM[2][1] << "\t" << nodeTM[3][1] << "\n";
	Log::Get() << nodeTM[0][2] << "\t" << nodeTM[1][2] << "\t" << nodeTM[2][2] << "\t" << nodeTM[3][2] << "\n";	
	Log::Get() << nodeTM[0][3] << "\t" << nodeTM[1][3] << "\t" << nodeTM[2][3] << "\t" << nodeTM[3][3] << "\n";
	Log::Get() << "\n";*/
}


void XmlSaver::SaveInverseWorldTransformMatrix(float *v)
{
	/*Log::Get() << "Inversed World Transform Matrix:\n";
	Log::Get() << nodeTM[0][0] << "\t" << nodeTM[1][0] << "\t" << nodeTM[2][0] << "\t" << nodeTM[3][0] << "\n";
	Log::Get() << nodeTM[0][1] << "\t" << nodeTM[1][1] << "\t" << nodeTM[2][1] << "\t" << nodeTM[3][1] << "\n";
	Log::Get() << nodeTM[0][2] << "\t" << nodeTM[1][2] << "\t" << nodeTM[2][2] << "\t" << nodeTM[3][2] << "\n";	
	Log::Get() << nodeTM[0][3] << "\t" << nodeTM[1][3] << "\t" << nodeTM[2][3] << "\t" << nodeTM[3][3] << "\n";
	Log::Get() << "\n";*/
}

void XmlSaver::SavePivotPoint(float x, float y, float z)
{
	//Log::Get() << "(" << pivotPoint.x << ", " << pivotPoint.y << ", " << pivotPoint.z << ")\n";
}
